/* 
 * Copyright 2011-2012 Andrew Brock
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.catchwa.myvideobrowser.gui;

import java.awt.BorderLayout;
import java.awt.Desktop;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JTextPane;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import org.apache.log4j.Logger;
import org.catchwa.myvideobrowser.Main;

/**
 *
 * @author Andrew Brock
 */
public class AboutDialog extends JDialog implements ActionListener {

  private static Logger log = Logger.getLogger(AboutDialog.class);
  private JButton okButton;

  public AboutDialog() {
    this.setLayout(new BorderLayout());
    this.setTitle("About My Video Browser");
    JTextPane textPane = new JTextPane();
    textPane.setEditable(false);
    textPane.setContentType("text/html");
    StringBuilder sb = new StringBuilder();
    sb.append("<html>");
    sb.append("<h2>My Video Browser</h2>");
    sb.append("Copyright Andrew Brock 2011-2012");
    sb.append("<br>");
    sb.append("Licensed under the <a href=\"http://www.apache.org/licenses/LICENSE-2.0.html\">Apache License, Version 2.0</a> (Refer to NOTICE.txt and LICENSE.txt in the program directory for further details)");
    sb.append("<br>").append("<br>");
    sb.append("<strong>Version: </strong>").append(Main.getVersion());
    sb.append("<br>");
    sb.append("<a href=\"http://code.google.com/p/my-video-browser\">http://code.google.com/p/my-video-browser</a>");
    sb.append("<br><br>");
    sb.append("This product uses the TMDb API but is not endorsed or certified by TMDb.");
    sb.append("<br>");
    sb.append("<img src=\"http://cf2.themoviedb.org/assets/380c5d587c8d4/images/tmdb-logo.png\" />");
    sb.append("</html>");
    textPane.setText(sb.toString());
    textPane.addHyperlinkListener(new HyperlinkListener() {

      @Override
      public void hyperlinkUpdate(HyperlinkEvent e) {
        if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
          try {
            Desktop.getDesktop().browse(e.getURL().toURI());
          } catch (Exception ex) {
            log.error("Error opening link", ex);
          }
        }
      }
    });
    this.add(textPane, BorderLayout.CENTER);

    okButton = new JButton("OK");
    okButton.addActionListener(this);
    this.add(okButton, BorderLayout.SOUTH);

    this.setSize(400, 350);
    this.setModal(true);
    this.setResizable(false);
    this.setVisible(true);
  }

  @Override
  public void actionPerformed(ActionEvent ae) {
    if (ae.getSource().equals(okButton)) {
      this.dispose();
    }
  }
}
